<?php

/**
 * Some rights reserved：abc3210.com
 * Contact email:admin@abc3210.com
 */
class PublicAction extends AdminbaseAction {

    //后台登陆界面
    public function login() {
        $this->display();
    }

    //后台登陆验证
    public function tologin() {
        
        $username = $this->_post("username");
        $password = $this->_post("password");
        $code = $this->_post("code");
        if(empty($username) || empty($password)){
            $this->error("用户名或者密码不能为空，请从新输入！",U("Public/login"));
        }
        if(empty($code)){
            $this->error("请输入验证码！",U("Public/login"));
        }
        //验证码开始验证
        if(!$this->verify($code)){
            $this->error("验证码错误，请重新输入！",U("Public/login"));
        }
        
        if(service("Passport")->loginAdmin($username,$password)){
            $this->success("登陆成功！",U("Admin/Index/index"));
        }else{
            $this->error("用户名或者密码错误，登陆失败！",U("Public/login"));
        }
    }
    
    //退出登陆
    public function logout() {
        if(service("Passport")->logoutLocal()){
            $this->assign("jumpUrl", U("Admin/Public/login"));
            $this->success('登出成功！');
        }
        
    }
    
}

?>
